﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Truextend.CoffeShop.Model;

namespace Truextend.CoffeShop.DataAccess
{
    public static class OrdersDataAccess
    {

        static CoffeShopEntities db = new CoffeShopEntities();

        public static List<Order> GetOrdersForState(string state)
        {
            List<Order> list_orders = new List<Order>();

            try {

                list_orders = (from p in db.Order where p.State == state select p).ToList();

            }
            catch (Exception) { }

            return list_orders;
        }

        public static void AddOrder(Order order) {

            try {
                db.AddToOrder(order);
                db.SaveChanges();
            }
            catch (Exception) { }
        }

        public static Order GetLastOrder() {

            Order order = new Order();

            try { 
                
                order = (from p in db.Order orderby p.OrderId descending select p).First();

            }catch(Exception){}

            return order;
            
        }

        public static Order GetOrderById(int orderId) {
            Order order = new Order();

            try {                 
                order = (from p in db.Order where p.OrderId == orderId select p).First();
            }
            catch (Exception) { }

            return order;
        }
    }
}
